package com.springboot.web;

import com.springboot.interceptor.UerInterceptor;
import com.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Retention;
@Controller
@RequestMapping(value = "/user")
public class UserController {

    //用户登录请求
    @RequestMapping(value = "/login")
    public @ResponseBody Object login(HttpServletRequest request){

        User user = new User();
        user.setId(1001);
        user.setUsername("sm");
        request.getSession().setAttribute("user",user);
        return "login success";
    }
    //该请求需要用户登录才能访问
    @RequestMapping(value = "/center")
    public @ResponseBody Object center(){
        return "See center message";
    }
    //该请求不登录也能看到的
    @RequestMapping(value = "/out")
    public @ResponseBody Object out(){
        return "out see anytime";
    }
    //如果用户未登录访问了需要登录才能访问的请求，之后会跳转到该请求路径
    @RequestMapping(value = "/error")
    public @ResponseBody Object error(){
        return "error";
    }
}
